import { computed } from 'vue';
import { Company } from '@/types/company';

type CompanyProps = Readonly<{
    isAdd: boolean;
    visible: boolean;
    editCompany: Company;
}>;

export function useCompany(props: CompanyProps, emit: any) {
    const dialogVisible = computed({
        get() {
            return props.visible;
        },
        set(value: boolean) {
            emit('update:visible', value);
        },
    });

    const company = computed(() => props.editCompany);

    const okClick = () => {
        dialogVisible.value = false;
        emit('updateCompany', company.value);
    };

    const cancelClick = () => {
        dialogVisible.value = false;
    };

    return {
        dialogVisible,
        company,
        okClick,
        cancelClick,
    };
}
